#include "heightmapMgr.h"
#include <cassert>

cHeightmapMgr gHeightmapMgr;
cHeightmapMgr::cHeightmapMgr()
{

}
void cHeightmapMgr::PushHeightmap(string heightmappath,int rows,int cols,float offset,float scale,string heightmapKey)
{
	cHeightmap* pHeightmap = new cHeightmap;
	pHeightmap->SetOffset(offset);
	pHeightmap->SetScale(scale);
	pHeightmap->LoadRAW(heightmappath,rows,cols);
	if(mapHeightmap.find(heightmapKey)==mapHeightmap.end())
	{
		mapHeightmap.insert(make_pair(heightmapKey,pHeightmap));
	}
}
cHeightmap* cHeightmapMgr::GetHeightmap(string heightmapKey)
{
	assert(mapHeightmap.find(heightmapKey)!=mapHeightmap.end());
	return mapHeightmap[heightmapKey];
}
void cHeightmapMgr::EraseHeightmap(string heightmapKey)
{
	if(mapHeightmap.find(heightmapKey)!=mapHeightmap.end())
	{
		mapHeightmap.erase(heightmapKey);
	}
}
void cHeightmapMgr::Release()
{
	auto itr = mapHeightmap.begin();
	while(itr!=mapHeightmap.end())
	{
		delete itr++->second;
	}
}

//////////////////////////////////////////////////////////////////////////
cHeightmapMgr* GetHeightmapMgr()
{
	return &gHeightmapMgr;
}


